package cn.hicard.risk.dao.sys.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hicard.core.Page;
import cn.hicard.core.PageResult;
import cn.hicard.core.Where;
import cn.hicard.risk.dao.BaseDao;
import cn.hicard.risk.dao.sys.NoticeDao;
import cn.hicard.risk.entity.SysNotice;

@Repository
public class NoticeDaoImpl extends BaseDao<SysNotice> implements NoticeDao {

	@Override
	public void delete(int pk) throws Exception {
		super.delete(pk);
	}

	@Override
	public SysNotice getByPk(Integer pk) throws Exception {
		return super.getByPk(pk);
	}

	@Override
	public SysNotice getNewest() throws Exception {
		String hql = "FROM SysNotice ORDER BY publisTime DESC LIMIT 1";
		List<SysNotice> list = super.findByHql(hql);
		if(list != null && list.size()>0){
			return list.get(0);
		}
		return null;
	}

	@Override
	public PageResult<SysNotice> search(Where where, Page page) throws Exception {
		String listHql = "FROM SysNotice WHERE 1=1 " + where.queryString() + " ORDER BY publisTime DESC";
		String countHql = "SELECT COUNT(*) FROM SysNotice WHERE 1=1 " + where.queryString();
		PageResult<SysNotice> pr = new PageResult<SysNotice>();
		pr.setDataList(super.findByHqlPage(listHql, page, where.getParams()));
		pr.setResultCount(super.findCountByHql(countHql, where.getParams()));
		return pr;
	}


}
